[#ftl]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色管理</title>
 
<script type="text/javascript">
	
// 注册各种事件
$(function() {
	// 修改
	$("#uUpdate").click(function(){
		// 检查是否只选择一个
		var len = $("input[type='checkbox'][name='cb']:checked").length;
		if ( len== 0) {
			d=dialog({
            	content: '请选择一条数据！',
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
			    d.close().remove();
			}, 2000);
	        return false;
	     }else if(len>1){
	    	 d=dialog({
            	content: '一次只能修改一个角色！',
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
			    d.close().remove();
			}, 2000);
	     	return false;
	     }
 		// 初始值设定
 		var detailid=0;
		 $("input[name='cb']").each(function(){
             if($(this).attr("checked")=="checked"){
	        	detailid = $(this).attr("mid");
            }
        });		
		$("#id").val(detailid);
		
		d=dialog({
			url:'${base}/system/role/update?id='+detailid, 
		    title: '修改角色',
		    background: '#EEE', // 背景色
		    opacity: 0.05,  // 透明度
		    width: 600,
		    height: 540
		  });	
		  d.show();			
	});

	// 添加
	$("#uAdd").click(function(){
    	 d=dialog({
    	    url:'${base}/system/role/add', 
    	    title: '添加角色',
    	    background: '#EEE', // 背景色
    	    opacity: 0.05,  // 透明度
    	    width: 600,
    	    height: 540
    	  }); 		
    	d.show();	
	});
 
});
// 页面初始化
$(function() {
    originalpages(${pager.page},${pager.pages},"${base}/system/roles/",${module});
});

[#------------------------------------------------]
var d;
function closeArtDialog(){
    d.close().remove();
}
    
function deleteRole(param)
{    var thisNode=$(param).parent().parent();
     var roleid=thisNode.find("input:eq(0)").attr("value");
     $.ajax({
	       type : "post",
	       url : "${base}/system/role/isUser/"+roleid,
		   traditional:true,
		   dataType: "json",
		   success: function(data){	
			    if (!extendMessages(data).isAllSuccess()) {
    				d=dialog({
    	            	content: '已为该角色分配用户,无法删除该角色！',
    	                icon: 'succeed',
    	                fixed: true,
    	                lock: true,
    	            });
    	            d.show();
    	            setTimeout(function () {
    				    d.close().remove();
    				}, 2000);
		            return false;
				}else{
                	if(confirm("确定要删除这项数据吗？")) {
                	   $.ajax({
                	       type : "post",
                	       url : "${base}/system/role/delete/"+roleid,
                		   traditional:true,
                		   dataType: "json",
                		   success: function(data){	
                    		    noty({
                                      text:extendMessages(data).msg.message,
                                      layout:"center",
                                      timeout:2000,
                                      callback:{
                                         afterClose:function(){
                                            thisNode.remove(); 
                                         }
                                      }
                                    });
                			}
                		});[#--end .ajax --]
                	}[#--end if --]
                }[#--end else --]
            } [#--end success --]
		});[#--end ajax --]
} [#--end function deleteRole --]

</script>
</head>
<body> 
<div class="right_top"><span class="pl20 f14">角色管理</span></div>
<!-- 数据信息开始 -->
<div class="date_list">
		<div class="ml10 mt10">
           <input type="button" class="btn_1" value="添加" id="uAdd" />
           <input type="button" class="btn_1" value="修改" id="uUpdate" />
		 </div> 
		 <div id="tblReuslt" class="mb10 center">
		  <form id="queryForm" class="">
		  <div class="date_table_3 tc">
		    <input type="hidden" name="id"  id="id"/>
			<table class="mt10 ml10 exchange_table" style="width:100%;">
			   <tbody>
					<tr >
						<th class="color_2 tab_bt tab_t tab_bl w30"></th>
						<th class="color_2 tab_bt tab_t w50">序号</th>
						<th class="color_2 tab_bt tab_t w150">名称</th>
						<th class="color_2 tab_bt tab_t w150">编码</th>
						<th class="color_2 tab_bt tab_t">描述</th>
						<th class="color_2 tab_bt tab_t">操作</th>
					</tr>
			[#if roles?exists]
			   [#list roles as item]
					<tr>
					    <input type="hidden" value="${item.id!}">
						<td class="br tab_bt tab_bl">
						  <input type="checkbox" name="cb" mid="${item.id!}"/>
					    </td>
						
						<td class="br tab_bt tr">
						${showid[item_index]!}
					    </td>
						<td class="br tab_bt tl">
                        ${(item.name)!""}
					    </td>
                        <td class="br tab_bt tl">
                        ${(item.value)!""}
					    </td>

						<td class="br tab_bt tl">
						${(item.description)!""}
					    </td>
					    
					    <td class="br tab_bt">
						<a href="javaScript:void(0);" onclick="deleteRole(this)" class="no_tdn color_2">删除</a>
					    </td>
					
					</tr>
				[/#list]
			 [/#if]
			  </tbody>
			</table>
			</div>
		 </form>	
	</div>

	<!-- 页码显示 -->
	<div class="ChangePage01">
	   <div id="page" class="page"></div> 			
    </div>
</div>
<!-- 数据信息结束 -->
 
			<!-- 角色权限列表结束 -->
<div class="bottom"> </div>
</div>
 
		
</body>		
</html>